package com.listdemo;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.ArrayList;

/**
 * @Auther: shiquan
 * @Date: 2024/10/17 - 10 - 17 -15:14
 */
public class Test2 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        //添加元素
        //jdk5 int Integer 之间可以相互转换
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //遍历集合
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            //最后一个索引
            if (i == list.size() - 1){
                System.out.print(list.get(i));
            }else{
                System.out.print(list.get(i) + ",");
            }
        }
        System.out.println("]");
    }
}
